package org.zhang.shortlink.admin.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.zhang.shortlink.admin.dto.req.ShortLinkGroupSaveDTO;
import org.zhang.shortlink.admin.dto.req.ShortLinkGroupUpdateDTO;
import org.zhang.shortlink.admin.dto.resp.ShortLinkGroupVO;
import org.zhang.shortlink.admin.service.GroupService;
import org.zhang.shortlink.common.convention.result.Result;
import org.zhang.shortlink.common.convention.result.Results;

import java.util.List;

/**
 * 短链接分组接口
 */
@RestController
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * 新增短链接分组
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSaveDTO groupSaveDTO){
        return Results.success(groupService.saveGroup(groupSaveDTO.getGroupName()));
    }

    /**
     * 获取短链接列表
     */
    @GetMapping("/api/short-link/admin/v1/group/list")
    public Result<List<ShortLinkGroupVO>> getShortLinkGroupList(){
        return Results.success(groupService.getShortLinkGroupList());
    }

    /**
     * 修改短链接分组名
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateDTO groupUpdateDTO){
        return Results.success(groupService.updateGroup(groupUpdateDTO));
    }

    /**
     * 删除短链接分组
     */
    @DeleteMapping("/api/short-link/admin/v1/group/{gid}")
    public Result<Void> deleteGroup(@PathVariable String gid){
        return Results.success(groupService.deleteGroup(gid));
    }
}
